import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  //主页使用的路由
  {//自定义路由
    path: '/teacher', //path路径
    component: Layout, //布局 不需要改
    redirect: '/teacher/table', //重定向加载 
    name: '教师管理', //名称
    meta: { title: '教师管理', icon: 'el-icon-s-help' },
          //显示标题 图标
    children: [//component: Layout布局中的配置
      {
        path: 'table',//子路径的配置
        name: '教师列表',
        component: () => import('@/views/edu/teacher/list'),//使用的组件页面 非路由路径
        meta: { title: '教师列表', icon: 'table' }
      },
    ]
  },

  {
    path: '/student',
    component: Layout,
    redirect: '/student/list', 
    name: '学生管理', //名称
    meta: { title: '学生管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: '学生列表',
        component: () => import('@/views/edu/student/list'),
        meta: { title: '学生列表', icon: 'table' }
      },
      {
        path: 'save',
        name: '学生成绩',
        component: () => import('@/views/edu/student/save'),
        meta: { title: '学生成绩', icon: 'tree' }
      },
    ]
  },
  
  {
    path: '/test',
    component: Layout,
    redirect: '/test/list', 
    name: '试卷管理', //名称
    meta: { title: '试卷管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: '试卷列表',
        component: () => import('@/views/edu/test/list'),
        meta: { title: '试卷列表', icon: 'table' }
      },
      {
        path: 'save',
        name: '试卷题目',
        //步骤条第一步页面
        component: () => import('@/views/edu/test/info'),
        meta: { title: '试卷题目', icon: 'tree' }
      },
      {
        path: 'submit',
        name: '批改提交',
        //步骤条第一步页面
        component: () => import('@/views/edu/test/submit'),
        meta: { title: '批改提交', icon: 'tree' }
      },
    ]
  },
////////////////////////////////////////
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
